//
//  RHContactUsCell.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/10/31.
//

#import "RHContactUsCell.h"
@interface RHContactUsCell()
@property (nonatomic ,strong) UIView *bgView;

@end
@implementation RHContactUsCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setupUI];
    }
    return self;
}

-(void)setDic:(NSDictionary *)dic
{
    _dic = dic;
    self.titleLab.text = [NSString stringWithFormat:@"%@:",dic[CellTitle]];
    self.contentLab.text = dic[CellContent];
    
    [self.titleLab sizeToFit];
    
    
    kWeakSelf;
   
    [self.titleLab mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.offset(self.titleLab.width+1);
    }];
}

-(void)setupUI
{
    self.contentView.backgroundColor = CFTabViewBgColor;
    UIView *bgView = kView;
    bgView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:bgView];
    bgView.backgroundColor = [UIColor whiteColor];
    self.bgView = bgView;
    
    _titleLab = [[QMUILabel alloc]init];
    _titleLab.textColor = kCOLOR_HEX(@"3F4443");
    _titleLab.text = @"Q";
    _titleLab.font = [UIFont systemFontOfSize:13];
    _titleLab.textAlignment = NSTextAlignmentLeft;
    [bgView addSubview:_titleLab];
    
    _contentLab = [[QMUILabel alloc]init];
    _contentLab.textColor = kCOLOR_HEX(@"3F4443");
    _contentLab.font = [UIFont systemFontOfSize:13];
    _contentLab.textAlignment = NSTextAlignmentLeft;
    _contentLab.numberOfLines = 0;
    [bgView addSubview:_contentLab];
    
    UIView *line = kView;
    line.backgroundColor = kCOLOR_HEX(@"EBEDF0");
    [bgView addSubview:line];
    
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.height.offset(1);
        make.bottom.mas_offset(0);
    }];
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] init];
    [self.contentLab addGestureRecognizer:tapGesture];
    
    [tapGesture.rac_gestureSignal subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
        NSString *callString = [NSString stringWithFormat:@"tel://%@",self.contentLab.text];
        if([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:callString]]){
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callString] options:@{} completionHandler:^(BOOL success) {
                
            }];
        }
      
    }];
    kWeakSelf;
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 15, 0, 15));
       
    }];
    
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.top.equalTo(weakSelf.contentLab);
    }];

    [self.contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.titleLab.mas_right).offset(3);
        make.right.mas_offset(-15);
        make.top.mas_offset(15);
        make.bottom.mas_offset(-15);
    }];
    
    
}


@end
